// pages/personal/personal_collections/personal_collections.js
var utils = require('../../../utils/util.js');
var httpUrl = getApp().globalData.httpUrl;
var codeName = getApp().globalData.codeName;
var userId = getApp().globalData.userId;
//ID删除发布信息
function del(that) {
  utils.http(httpUrl + "deleteCollect", {
    code: codeName,
    userid: userId,
    cateid: that.data.id,
    houseid: that.data.idd,
    merchantid:that.data.idt
  }, function (res) {
    console.log(res);
    that.getInfo();
    that.getShop();
  })
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selected: true,
    selected1: false,
    cateid:"",
    houseid:"",
    merchant:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getInfo();
    this.getShop();
  },

  //信息收藏   
  getInfo: function (e) {
    var that = this;
    utils.http(httpUrl + "getUserCollect", {
      code: codeName,
      userid: userId
    }, function (res) {
      var cateinfolist = [];
      for (var index in res.cate) {
        if (res.cate[index].content == undefined) {
          res.cate[index].content = "";
        }
        //文字截取
        var sub = res.cate[index].content.substring(0, 40);
        var subContent = sub + "...";
        that.setData({
          advlist: res.cate[index].advlist
        })
        that.data.advlist.length = 3;
        res.cate[index].collect = !res.cate[index].collect;

        var catePost = {
          advlist: that.data.advlist,
          subAdvlist: res.cate[index].advlist, //截取后的图片
          city: res.cate[index].city,
          code: res.cate[index].code,
          collectby: res.cate[index].collectby,
          content: res.cate[index].content,
          subContent: subContent,//截取后的属性
          createTime: res.cate[index].createTime,
          id: res.cate[index].id,
          index: res.cate[index].index,
          collect: res.cate[index].collect,
          ischoiceness: res.cate[index].ischoiceness,
          istop: res.cate[index].istop,
          lookby: res.cate[index].lookby,
          publishby: res.cate[index].publishby,
          title: res.cate[index].title,
          type: res.cate[index].type,
          user: res.cate[index].user,
          isstare: false
        }
        cateinfolist.push(catePost);
      }
      that.setData({
        cate: cateinfolist,
        house: res.house,
        user:res.user
      })
     // console.log(that.data.cate);
    })
  },
  //全文和收起
  noStareTap: function (e) {
    var index = e.currentTarget.dataset.index;
    this.data.cate[index].isstare = !this.data.cate[index].isstare;
    this.setData({
      cate: this.data.cate
    })
  },
  //商家收藏
  getShop: function (e) {
    var that=this;
    utils.http(httpUrl + "getmerchantUserCollect", {
      code: codeName,
      userid: userId
    }, function (res) {
      console.log(res);

     that.setData({
       merchant: res.merchant
     })
    })
  },
  //删除美食
  deltypemeishitap: function (e) {
    var id = e.currentTarget.dataset.id;
    this.setData({
      id: id,
      idd: "",
      idt: ""
    })
    del(this);
  },

  //删除房屋
  deltypejiajutap: function (e) {
    var idd = e.currentTarget.dataset.idd;
    this.setData({
      idd: idd,
      id: "",
      idt: ""
    })
    del(this);
   
  },
  //删除商家

  delshopptap: function (e) {
    var idt = e.currentTarget.dataset.idt;
    this.setData({
      idt: idt,
      id: "",
      idd: ""
    })
    del(this);
  },
  //点击头像进入个人主页
  // onPersonalHomeTap: function (e) {
  //   var modelid = e.currentTarget.dataset.modelid;
  //   wx.navigateTo({
  //     url: '../../gourmet/gourmet_details/gourmet_details?modelid=' + modelid,
  //   })
  // },

  selected: function (e) {
    this.setData({
      selected1: false,
      selected: true
    })
  },
  selected1: function (e) {
    this.setData({
      selected: false,
      selected1: true
    })
  }
})